<?php

namespace App\Admin\Actions\OrderAction;

use App\Models\Order;
use App\Services\AutoRefundProductOrder\AutoRefundProductOrder;
use Encore\Admin\Actions\RowAction;

class OrderRefund extends RowAction
{
    public $name = '退款';
    
    public function handle(Order $model)
    {
	    if (!$model->isPaid()) {
		    return $this->response()->error('目标订单未支付');
	    }  
    	
	    app(AutoRefundProductOrder::class, ['order' => $model])->refund();
	  
	    
	    return $this->response()->success('订单退款已提交')->refresh();
    }
	
	public function dialog()
	{
		$this->confirm('确定要退款当前订单，谨慎操作?');
	}
}
